import logging

from PyQt5.QtWidgets import QWidget, QDialog
from PyQt5.uic import loadUi

UI_Mapping = {}

class IVacBase:

    @classmethod
    def _load_ui_file(cls, uifile, wx_instance):
        logging.debug("IVacWidget::DEBUG -->> IVacWidget's sub-class [{}]'name is: {} ".format(cls, cls.__name__))  # 验证：cls.__name__呈现多态（子类类名）
        try:
            if not uifile:
                uifile = UI_Mapping[cls.__name__]
            loadUi(uifile, wx_instance)
        except KeyError:
            logging.error("Unable to find the Page[{}]".format(cls.__name__))

    def _active(self):
        """ 连接信号槽，激活widget模块的功能 """
        pass

    def _import(self):
        """ 载入数据 """
        pass


class IVacWidget(QWidget, IVacBase):  # component of view and controller
    def __init__(self, parent=None, uifile=None):
        super().__init__(parent)
        super()._load_ui_file(uifile, self)


class IVacDialog(QDialog, IVacBase):
    def __init__(self, parent=None, uifile=None):
        super().__init__(parent)
        super()._load_ui_file(uifile, self)
